//获取dom元素
var getdom = function(){
	this.$ = function(id){
		return document.getElementById(id);
	}

	this.getElementsByClass = function(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null )
                node = document;
        if ( tag == null )
                tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
                if ( pattern.test(els[i].className) ) {
                        classElements[j] = els[i];
                        j++;
                }
        }
        return classElements;
    }
    this.GetCurrentStyle = function(obj, prop){
	    if (obj.currentStyle){ //IE
	        return obj.currentStyle[prop];
	    }
	    else if (window.getComputedStyle){ //非IE
	        propprop = prop.replace (/([A-Z])/g, "-$1");
	        propprop = prop.toLowerCase ();
	        return document.defaultView.getComputedStyle(obj,null)[propprop];
	    }
	    return null;
	}
}
var newdom = new getdom;

function add_file(options){
  var len_add = options.length,
      arr_class = [],
      arr_id = [];

  for(var i = 0;i < len_add;i++){
    arr_class[i] = newdom.getElementsByClass(options[i])[0];
    arr_class[i].index = i;
    arr_id[i] = newdom.$(options[i]);

    arr_class[i].onclick = function(){
    	//console.log(arr_id[this.index])
    	arr_id[this.index].click();
    }
  }
} 
function show_file_name(obj_file,show_road_id){
	var obj_file = newdom.$(obj_file),
		show_road_id = newdom.$(show_road_id);
	if(obj_file){
		obj_file.onchange = function(){
			show_road_id.value = this.value;
		}
	}
}
function tool(obj,evt){
	//获取节点
	var obj = obj.nodeType ? obj : newdom.getElementsByClass(obj)[0];
	//console.log(obj.nodeType);
	switch(evt){
		//鼠标点击事件
		case "click" :
			obj.onclick = function(e){
				//获取事件触发元素
				var _e = window.event ? window.event : e || arguments[0],
					target = _e.target ? _e.target : _e.srcElement,
					json_list = newdom.$("json_list"),
					control_list = newdom.getElementsByClass("control_list"),
					checkbox = newdom.getElementsByClass("checkbox"),
					len_checkbox = checkbox.length;
				//选择所有工具
				if(target.className == "choice_all"){
					for(var i = 0;i < len_checkbox;i++){
						checkbox[i].checked = true;
					}
					
				}
				//选择删除工具
				if(target.className == "delect"){

					var src = "";
					for(var i = 0;i < len_checkbox;i++){
						//如果被选中，删除所在行
						if(checkbox[i].checked == true && checkbox[i].id){
							//control_list[i].parentNode.removeChild(control_list[i])
							src += checkbox[i].id + ":";

						}
					}
					console.log(src)
				}
			}
		break;
		//鼠标在元素上面
		case "mouse" :
			//do something
		break;
	}
}
function dele(eventobj,deleobj){
	var eventobj = newdom.getElementsByClass(eventobj),
		len_eventobj = eventobj.length,
		deleobj = newdom.getElementsByClass(deleobj);
	for(var i = 0;i < len_eventobj;i++){
		eventobj[i].index = i;
		eventobj[i].onclick = function(e){
			if(deleobj[this.index]){
				deleobj[this.index].parentNode.removeChild(deleobj[this.index])
			}
		}
	}
}
//弹窗调用函数，，，第一个参数text是提示内容，第二个参数为0时弹窗为信息弹窗，，为1时是判断弹窗,不填时是内容提示弹窗
function content_alert(text,num){
	if(document.all){
		alert(text)
	}
	else{
		var div = document.createElement("div");
		div.className = "alert_wrap";
		if(num){
			div.innerHTML = '<div class="content"><h4>温馨提示</h4><p class="alert_tip">'+text+'</p><a class="alert_sure">确定</a><a class="alert_no">取消</a></div>'
		}
		else{
			div.innerHTML = '<div class="content"><h4>温馨提示</h4><p class="alert_tip">'+text+'</p><a class="alert_no">确定</a></div>'
		}
		document.body.appendChild(div);

		var alert_sure = newdom.getElementsByClass("alert_sure")[0],
			alert_no = newdom.getElementsByClass("alert_no")[0],
			alert_wrap = newdom.getElementsByClass("alert_wrap")[0];
		if(alert_sure){
			alert_sure.onclick = function(){
				function_1();
				//document.body.removeChild(alert_wrap);
			}
		}
		alert_no.onclick = function(){

			document.getElementsByTagName("body")[0].removeChild(alert_wrap);
		}
		document.onkeydown = function(e){
          var _e = window.event ? window.event : e || arguments[0];
          if(_e.keyCode == 13){
            document.getElementsByTagName("body")[0].removeChild(alert_wrap);
            document.onkeydown = "";
          }

        }

			
		
	}	
}

//密码判别函数
	// judge({
	// 	kind : "password",判断的类型，这样是密码判断
	// 	kind_id : "password",//判断的那个id
	// 	kind_back_focus : 聚焦时触发的函数
	// 	kind_back_blur : 取消聚焦时触发的函数
	// })
function judge(options){
	var kind = options.kind,
		kind_id = document.getElementById(options.kind_id),
		kind_back_focus = options.kind_back_focus ? options.kind_back_focus : undefined,
		kind_back_blur = options.kind_back_blur ? options.kind_back_blur : undefined;
	kind_id.onfocus = function(){
		switch(kind){
			case "password" : 
				if(kind_back_focus){
					kind_back_focus();
				}			
				break;

		}
	}
	kind_id.onblur = function(e){
		switch(kind){
			case "password" :
 				if(kind_back_blur){
 					kind_back_blur();
 				}				
				break;
		}
	}
		
}
// judge({
// 	kind : "password",//必传
// 	kind_id : "password",//必传
// 	kind_back_focus : fn_focus,
// 	kind_back_blur : fn_blur
// })


function is_empty(arr,tip_arr){
	var len_arr = arr.length,
		new_arr = [],
		obj = [];
	for (var i = 0; i < len_arr; i++) {
		obj[i] = document.getElementById(arr[i]);
		if(obj[i].value == ""){
			new_arr.push(tip_arr[i]);
		}
	};
	return new_arr;
}

                        
var title = document.getElementById("title");
if(title){
  title.onkeyup = function(){
    if(title.value.length == 30){
      alert("标题字数不能大于30")
    }
  }
}





      
